#include<vector>
#include<string>
using namespace std;

class Solution {
public:
    string pushDominoes(string dominoes) {
        vector<int>power(dominoes.size(), 0);
        int maxPower = dominoes.size();
        int p = 0;
        for (int i = 0; i < dominoes.size(); ++i) {
            if (dominoes[i] == 'R')
                p = maxPower + 1;
            else if (dominoes[i] == 'L')
                p = 0;
            if (p != 0)
                power[i] = --p;
        }
        p = 0;
        for (int i = dominoes.size()-1; i>=0 ; --i) {
            if (dominoes[i] == 'L')
                p = maxPower + 1;
            else if (dominoes[i] == 'R')
                p = 0;
            if (p != 0)
                power[i] -= --p;
            if (power[i] > 0) dominoes[i] = 'R';
            else if (power[i] < 0) dominoes[i] = 'L';
            else dominoes[i] = '.';
        }
        return dominoes;
    }
};